function [result] = getvalue(method, data, dfile, x1, x2)
%
% get the value of data. uses dfile to make time base,
% x1, x2 are the window for the measurement, and data is the data....
% function is "vectorized" to handel data with multiple arrays...
%

t=make_time(dfile);
if(ndims(t) > 1)
    t = t(1,:);
end;
[x, t1] = findnear(t, x1);
[x, t2] = findnear(t, x2);

for k = 1:size(data,1)
    dx = data(k,:);

    switch(method)
        case {'mean', 'average', 'avg'}
            result(k) = mean(dx(t1:t2));
        case 'variance'
            result(k) = variance(x(t1:t2));
        case 'slope'
            [result(k), b, r, p] = linreg(t(t1:t2), data(t1:t2));
        case 'min'
            result(k) = min(data(t1:t2));
        case 'max'
            result(k) = max(data(t1:t2));
        otherwise
            result(k) = zeros(1, length(data));
    end;
end;
